package com.czg.jsonschema2lombokpojo;

import java.net.URI;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JType;

/**
 * 一个JSONschema文档。
 */
public class Schema {

    private final URI id;
    private final JsonNode content;
    private final Schema parent;
    private JType javaType;

    public Schema(URI id, JsonNode content, Schema parent) {
        this.id = id;
        this.content = content;
        this.parent = parent != null ? parent : this;
    }

    public JType getJavaType() {
        return javaType;
    }

    public void setJavaType(JType javaType) {
        this.javaType = javaType;
    }

    public void setJavaTypeIfEmpty(JType javaType) {
        if (this.getJavaType() == null) {
            this.setJavaType(javaType);
        }
    }

    public URI getId() {
        return id;
    }

    public JsonNode getContent() {
        return content;
    }

    public Schema getParent() {
        return parent;
    }

    public Schema getGrandParent() {
        if (parent == this) {
            return this;
        } else {
            return this.parent.getGrandParent();
        }
    }

    public boolean isGenerated() {
        return javaType != null;
    }

}
